package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.ReceivableDetail;
import com.intelligent.service.impl.ReceivableDetailServiceImpl;
import com.intelligent.utils.Result;
import com.intelligent.vo.ReceivableDetailPageReq;
import com.intelligent.vo.ReceivableDetailResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/receivable-detail")
public class ReceivableDetailController {

    @Autowired
    private ReceivableDetailServiceImpl service;

    @PostMapping("/page")
    public Result<Page<ReceivableDetailResp>> page(@RequestBody ReceivableDetailPageReq req) {
        Page<ReceivableDetailResp> page = service.page(req);
        return Result.success(page);
    }

    @GetMapping("/{id}")
    public Result<ReceivableDetailResp> detail(@PathVariable Long id) {
        ReceivableDetailResp resp = service.detail(id);
        return resp == null ? Result.error("未找到明细") : Result.success(resp);
    }

    @PostMapping("/create")
    public Result<?> create(@RequestBody ReceivableDetail detail) {
        boolean ok = service.create(detail);
        return ok ? Result.success(detail) : Result.error("保存失败");
    }
}



